#ifndef __STDFTX_H__
#define __STDFTX_H__

//#include "FortiError.h"

#if defined(WIN32) || defined(_WIN32_WCE)
	#define PLATFORM_WINDOWS
#elif defined(__SYMBIAN32__)
	#define PLATFORM_SYMBIAN
#else
	#error "Unknown Platform !!!"
#endif

//////////////////////////////////////////////////////////////////////////
//		Common Definitions
//////////////////////////////////////////////////////////////////////////
#define MAX_PASSWORD_LEN		20


//MACRO FOR WINDOWS & WINDOWS MOBILE
#ifdef PLATFORM_WINDOWS
	#include <windows.h>

	//MACROS to compatible with Symbian
	#define IMPORT_C	__declspec(dllexport)
	#define EXPORT_C	__declspec(dllexport)
	
	//MACROS to redefine Window style stdlib file functions
	#define wfopen	_wfopen
//	#define wmkdir _wmkdir
	#define wrmdir RemoveDirectory
	#define wrename	MoveFile
	#define wunlink	DeleteFile
	#define wchdir	SetCurrentDirectory
	#define wmkdir(a)	CreateDirectory(a,NULL)
//	#define wrmdir	RemoveDirectory
	#define wgetcwd(buf,len) GetCurrentDirectory(len,buf)
	
	//Dummy functions of wsprintf
	#define wsprintf1 wsprintf
	#define wsprintf2 wsprintf
	#define wsprintf3 wsprintf

#else		//PLATFORM_WINDOWS
	#include <e32std.h>         // GLDEF_C
	#include <f32file.h>
	#include <libc/stddef.h>
	#include <libc/string.h>
	#include <libc/stdlib.h>
	#include <libc/sys/unistd.h>
	#include <libc/sys/stat.h>


	//Type definition to compatible with Windows
	typedef unsigned char byte;
	typedef byte BYTE;
	typedef unsigned short WORD;
	typedef unsigned int UINT;
	typedef int INT;
	typedef long BOOL;
	typedef long LONG;
	typedef unsigned long DWORD;
	typedef char CHAR;
	typedef wchar_t WCHAR;
	typedef wchar_t TCHAR;
	typedef void VOID;
	typedef void* HANDLE;

	//Two Windows time structures
	typedef struct  _FILETIME
		{
		DWORD dwLowDateTime;
		DWORD dwHighDateTime;
		}	FILETIME;

	typedef struct  _SYSTEMTIME
		{
		WORD wYear;
		WORD wMonth;
		WORD wDayOfWeek;
		WORD wDay;
		WORD wHour;
		WORD wMinute;
		WORD wSecond;
		WORD wMilliseconds;
		}	SYSTEMTIME;

	///TCHAR related macros
	#define _T(x)		L##x
	#define _tcslen		wcslen
	#define _tcscat		wcscat
	#define _tcscpy		wcscpy
	#define _tcsncpy	wcsncpy
	#define _tcsicmp	wcscasecmp

	//HANDLE related MACROS
	#define DECLARE_HANDLE(name) struct name##__ { int unused; }; typedef struct name##__ *name
	#define INVALID_HANDLE_VALUE (HANDLE)-1

	//File attribute definition to compatible with Windows
	#define FILE_ATTRIBUTE_READONLY             0x00000001  
	#define FILE_ATTRIBUTE_HIDDEN               0x00000002  
	#define FILE_ATTRIBUTE_SYSTEM               0x00000004  
	#define FILE_ATTRIBUTE_DIRECTORY            0x00000010  
	#define FILE_ATTRIBUTE_ARCHIVE              0x00000020  
	#define FILE_ATTRIBUTE_ENCRYPTED            0x00000040  
	#define FILE_ATTRIBUTE_NORMAL               0x00000080  
	#define FILE_ATTRIBUTE_TEMPORARY            0x00000100  
	#define FILE_ATTRIBUTE_SPARSE_FILE          0x00000200  
	#define FILE_ATTRIBUTE_REPARSE_POINT        0x00000400  
	#define FILE_ATTRIBUTE_COMPRESSED           0x00000800  
	#define FILE_ATTRIBUTE_OFFLINE              0x00001000  
	#define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED  0x00002000  


	//Dummy functions of wsprintf
	#define wsprintf1(a,b,c)				\
	{										\
		TPtr16 p((TText16*)a,0,260);		\
		TPtrC16 fmt( (const TText16*)b );	\
		p.Format(fmt,c);					\
		p.PtrZ();							\
	}

	#define wsprintf2(a,b,c,d)				\
	{										\
		TPtr16 p((TText16*)a,0,260);		\
		TPtrC16 fmt( (const TText16*)b );	\
		p.Format(fmt,c,d);					\
		p.PtrZ();\
	}

	#define wsprintf3(a,b,c,d,e)			\
	{										\
		TPtr16 p((TText16*)a,0,260);		\
		TPtrC16 fmt( (const TText16*)b );	\
		p.Format(fmt,c,d,e);				\
		p.PtrZ();							\
	}

	//HELPER MACROS for Symbian
	#ifndef TRUE
		#define TRUE 1
	#endif

	#ifndef FALSE
		#define FALSE 0
	#endif
	
	#ifndef MAX_PATH
		#define MAX_PATH 260
	#endif

	#ifndef min
		#define min(a,b) (((a) < (b)) ? (a) : (b))
	#endif	//min

	#ifndef max
		#define max(a,b) (((a) > (b)) ? (a) : (b))
	#endif	//max

#endif	//PLATFORM_WINDOWS


#ifdef PLATFORM_SYMBIAN
	#ifdef EKA2
		#define DECLARE_DLL_ENTRY()	\
			GLDEF_C TInt E32Main()	{ return KErrNone; }
	#else
		#define DECLARE_DLL_ENTRY()	\
			GLDEF_C TInt E32Dll( TDllReason ) { return KErrNone; }
	#endif
#else	//PLATFORM_SYMBIAN
	#define DECLARE_DLL_ENTRY()	\
		BOOL APIENTRY DllMain( HANDLE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved ) { return TRUE; }
#endif	//PLATFORM_SYMBIAN

#endif	//__STDFTX_H__
